﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/EditWidows/eYUITreeList.Master" CodeBehind="PYUITreeList.aspx.cs" Inherits="ZX.WebApp.EditWidows.PYUITreeList" %>

  <%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls" TagPrefix="cc1" %>

     <asp:Content ContentPlaceHolderID="headerPlace" runat="server">
       <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/paginator/assets/skins/sam/paginator.css" />
        <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />
    <!--begin custom header content for this example-->
    <style type="text/css">
    .yui-skin-sam table {
	    width: 100%;
    }
    #tree {background: #fff; padding:1em;}
    #button-example-form fieldset, 
    #button-example-form fieldset div {
        border: 2px groove #ccc;
        margin: .5em;
        padding: .5em;

    }
    .yui-button#pushbutton2 button,
    .yui-button#pushbutton5 button, 
    .yui-button#pushbutton4 button,
    .yui-button .Add button {
        background: url(../button/assets/add.gif) center center no-repeat;
        text-indent: -4em;
        overflow: hidden;
        padding: 0 .75em;
        width: 2em;
        *margin-left: 4em;   /* IE only */
        *padding: 0 1.75em;  /* IE only */
    }  
    .yui-button#pushbutton3 button,
    .yui-button#pushbutton6 button, 
    .yui-button#pushbutton9 button {
        padding-left: 2em;
        background: url(../button/assets/add.gif) 10% 50% no-repeat; 
    }
    <% =DataTableCss %>
</style>
    <!--end custom header content for this example-->
    <!-- Dependencies -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/treeview/treeview-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
     <script type="text/javascript" src="../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
     </asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderControl" runat="server">
    <button type="button" id="btnCheck" name="btnCheck">
        批量新增</button>   <%= BtnItems %>
    <button type="button" id="btnFull" name="btnFull">
        全屏</button>
    <button type="button" id="btnReload" name="btnReload">
        刷新</button>
   <span style="display:none"> <button type="button" id="btnClose" name="btnClose">     
        关闭当前页</button>   </span>
    <script type="text/javascript">
    YAHOO.example.init = function () {
         function onButtonClick(p_oEvent) {
                 switch(this.get("id"))
                 { 
                  case "btnCheck":
                        fnAddPosition();
                        break;     
                  <% =InitBtnEvents %>
                    case "btnFull": 
                         fnFull();
                         break;
                    case "btnClose":
                         fnAddMasterDetail();
                         break;
                    case "btnReload":
                         fnReload();
                         break;                  
                    default:

                         break;
                 }                        
        }
        YAHOO.util.Event.onContentReady("toolbar", function () {
              <% =BtnEvents  %>
            var btnCheck = new YAHOO.widget.Button("btnCheck");
            btnCheck.on("click", onButtonClick); 
        var btnFull = new YAHOO.widget.Button("btnFull");
        btnFull.on("click", onButtonClick);
        var btnClose = new YAHOO.widget.Button("btnClose");
        btnClose.on("click", onButtonClick);
        var btnReload = new YAHOO.widget.Button("btnReload");
        btnReload.on("click", onButtonClick);
        });      
    } ();
    </script>
</asp:Content>

<asp:Content ID="Content3"  ContentPlaceHolderID="leftPlaceHoder" runat="server">
    <cc1:TreeView ID="treeDiv1" runat="server" TableName='SysFunction' Caption='Name' Key='FunctionID' ParentKey='ParentID' path='FunctionPath'></cc1:TreeView>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="DataPlaceHolder" runat="server">
            <div id="search" style="display:none">
                <select id="drpSearch">
                    <option selected="selected" value="CustomerName">客户名称</option>
                    <option value="Code">客户编码</option>
                </select>
                <input type="text" id="txtSearch" name="txtSearch" />
                <input type="button" id="btnSearch" name="btnSearch" value="查找" style="width:50px; text-align:center;" />
            </div>       
            <div id="json">
            </div>
             <div id="bottom">
                <div id="pagetotal" style="float:left;height:25px; padding:8px;margin-top:3px;width:100px;"></div><div id="page" style="float:left"></div> 
            </div>
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">

   <!-- 通用方法 -->
<script src="../Scripts/common.js" type="text/javascript"></script>
<!-- 定义数据格式化方法 -->
<script src="../Scripts/yui.list.dataformat.js" type="text/javascript"></script>
<!--  用于加载自定义脚本 -->
<script src="../Scripts/appjs/model.<% =EntityName %>.js" type="text/javascript" language="javascript"></script> 
<script type="text/javascript" src="../Scripts/yui.list.YUITreeList.js"></script>
    <script type="text/javascript">
    var PageTotal;
var pageindex = 1;
var pagesize = 25;

    var const_entityName="<%=EntityName%>",
    fkey="00000000-0000-0000-0000-000000000000",
     const_functionId   ="<% =FunctionID %>",//自定义条件
     const_EditEntity = "<% =EditEntity %>",//编辑实体名
         const_Order ="<% =Order %>",           //排序  
        const_UserId = "<% = UserId %>",       //
        const_DataFields = [<% =DataFields %>],
        const_DataColums = [<% =DataColums %>],
         SaveUrl,dl;
        const_EditWindowWidth = "<% =EditWindowWidth %>px",
		const_EditWindowHeight = "<% =EditWindowHeight %>px",
        const_CustomCondition = encodeURI("<% =DefineCondition %>"),//查询方案条件
        const_PageTitle=encodeURI("<% =PageTitle %>"),
       initialRequestUrl="entity=<%=EntityName%>&order=<% =Order %>&zip=94089&results=10&output=json&r="+Math.random()+"&condition="+window.decodeURI("<%=ForeignKey%>='"+fkey+"'");
     const_entityID = "<% =EntityId %>";  //实体ID名称
     (function() {
        var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event;
 
        Event.onDOMReady(function() {
            var layout = new YAHOO.widget.Layout({
                minWidth: 1000,
                minHeight: 500,
                units: [
                    { position: 'left', width: 200, resize: true, body: 'left', gutter: '2px 0px', collapseSize: 50, scroll: true, maxWidth: 300 },
                    { position: 'center', minWidth: 400, minHeight: 200 }
                ]
            });
            layout.on('render', function() {
                var el = layout.getUnitByPosition('center').get('wrap');
                var layout2 = new YAHOO.widget.Layout(el, {
                    parent: layout,
                    minWidth: 400,
                    minHeight: 200,
                    units: [
                        { position: 'top', body: 'toolbar', height: 35, gutter: '1px', maxHeight: 80 },
                        { position: 'bottom',  height: 35, resize: true, body: 'bottom', gutter: '1px', maxHeight: 130 },
                        { position: 'center', body: 'data', gutter: '1px', scroll: true }
                    ]
                });
                layout2.render();
            });
            layout.render();
            InitLeftData();
        });
    })();
    function InitLeftData(){
		    var tree1 = new YAHOO.widget.TreeView("treeDiv1");
		    tree1.setNodesProperty('propagateHighlightUp',true);
		    tree1.setNodesProperty('propagateHighlightDown',true);
		    tree1.subscribe('clickEvent',tree1.onEventToggleHighlight);	
		    tree1.render();
            tree1._nodes[1].expand();
            BindData();
        }

    function Native(caption,key){  
      fkey=key;
      initialRequestUrl="entity=<%=EntityName%>&order=<% =Order %>&zip=94089&results=10&output=json&r="+Math.random()+"&condition="+window.decodeURI("<%=ForeignKey%>='"+fkey+"'");
      BindData();
      GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + initialRequestUrl);
      //window.location.href='Extend/YUIList.aspx?entity=SysRole';
    }
    var _fn, _ids;
    var GetSelected=function(ids){
        _ids=ids
    }
     var mDataTable;
function BindData() {
    YAHOO.example.XHR_JSON = function() {
    
        var formatUrl = function(elCell, oRecord, oColumn, sData) {
            elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
        };      
        var formatRating = function(elCell, oRecord, oColumn, sData) {
            elCell.innerHTML = (sData === null) ? "N/A" : YAHOO.util.Number.format(sData);
        };
        var myColumnDefs = [
              <% =DataFields %>
        ];
        var myDataSource = new YAHOO.util.DataSource("../Extend/AjaxData/JSONList.aspx?");
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
        myDataSource.connXhrMode = "queueRequests";
       myDataSource.responseSchema = {
            resultsList: "rows",
            metaFields: { totalRecords: "total" },
            fields: const_DataColums
        };
       this.myDataTable = new YAHOO.widget.DataTable("json", myColumnDefs,
                    myDataSource,
                    { initialRequest: initialRequestUrl
                    , selectionMode: "single"
                    });
        mDataTable =this.myDataTable;
        var mySuccessHandler = function() {
            this.set("sortedBy", null);
            this.onDataReturnAppendRows.apply(this,arguments);
        };
        var myFailureHandler = function() {
            this.showTableMessage(YAHOO.widget.DataTable.MSG_ERROR, YAHOO.widget.DataTable.CLASS_ERROR);
            this.onDataReturnAppendRows.apply(this,arguments);
        };
        var callbackObj = {
            success : mySuccessHandler,
            failure : myFailureHandler,
            scope : myDataTable
        };
      
	         // 注册相关方法给相关事件
        this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow);
        this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow);
        this.myDataTable.subscribe("rowClickEvent", this.myDataTable.onEventSelectRow);
        this.myDataTable.subscribe("cellClickEvent", this.myDataTable.onEventShowCellEditor);

        this.myDataTable.subscribe("checkboxClickEvent", function (oArgs) {
            var elCheckbox = oArgs.target;
            var oRecord = this.getRecord(elCheckbox);
            oRecord.setData("iSun_Selected", elCheckbox.checked);
        });
        this.myDataTable.selectRow(this.myDataTable.getTrEl(0));    
        hideCol();
    }();
}

//--分页使用
GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + initialRequestUrl);
  //获取列表选中的值
     function Save(){
        var list = this.mDataTable.getRecordSet()._records;
        var elist = [];
        dl = [];
       for (var i = 0; i < list.length; i++) {
            if (list[i]._oData["iSun_Selected"] == true) {
                 elist.push(list[i]._oData[const_entityID]);
            }
        }
     //var recordID = mDataTable.getSelectedRows()[0];;
     alert(elist.join(','));
   }
   function RefreshData() {
      initialRequestUrl = "pageindex=1&entity=" + const_entityName + "&order=" + const_Order + "&r=" + Math.random() + "&zip=94089&results=10&output=json&functionid=" + const_functionId + "&customCondition=" + decodeURI(const_CustomCondition);
      BindData();
      ReLoadData();
}
/*刷新时候调用*/
function ReLoadData() {
    var requestStr = "pagesize=" + pagesize + "&pageindex=" + pageindex + "&entity=" + const_entityName + "&order=" + const_Order + "&r=" + Math.random() + "&zip=94089&results=10&output=json&functionid=" + const_functionId + "&customCondition=" + decodeURI(const_CustomCondition);
    GetTotal("../Extend/AjaxData/JSONList.aspx?onlyTotal=true&" + requestStr);
    mDataTable.requery(requestStr);
    //BindData();
}

// 用于数据刷新
YAHOO.widget.DataTable.prototype.requery = function (newRequest) {
    var ds = this.getDataSource();
    if (ds instanceof YAHOO.util.LocalDataSource) {
        ds.liveData = newRequest;
        ds.sendRequest("",
			{
			    success: this.onDataReturnInitializeTable,
			    failure: this.onDataReturnInitializeTable,
			    scope: this
			}
		);
    } else {
        ds.sendRequest(
			(newRequest === undefined ? this.get('initialRequest') : newRequest),
			{
			    success: this.onDataReturnInitializeTable,
			    failure: this.onDataReturnInitializeTable,
			    scope: this
			}
		);
    }
};
function closeWin(){
    YAHOO.example.container.dialog1.hide();
    Native("",fkey);
}
//隐藏/栏位
function hideCol(){ mDataTable.hideColumn(parseInt(0)); mDataTable.refreshView(); };
//YAHOO.util.Event.addListener(window, "load", BindData);
YAHOO.namespace("example.container");
 
YAHOO.util.Event.onDOMReady(function () {
	var handleSubmit = function() {
        var editwindow = document.getElementById("EditUIWindow");
        if(editwindow)
        {
           editwindow.contentWindow.Save();
        }
	}; 
	var handleCancel = function() {
		this.cancel();
	};
	var handleSuccess = function(o) {
		var response = o.responseText;
		response = response.split("<!")[0];
		document.getElementById("resp").innerHTML = response;
	};
	var handleFailure = function(o) {
		alert("Submission failed: " + o.status);
	};
    var handleCancel1= function() {
		        this.cancel();
	        };
    var callback =
        {
            success: handleSuccess1,
            failure: handleFailure1,
            argument: { foo: "foo", bar: "bar" }
        };
    var handleSubmit1 = function() {
      var editwindow1= document.getElementById("EditUIWindow1");
        if(editwindow1)
        {
           editwindow1.contentWindow.Save(fkey);
        }
            alert("设置成功");

            this.cancel();
	};
    var handleSuccess1 = function(o) {
	   alert("设置成功");
      this.cancel();
	};
	var handleFailure1 = function(o) {
        alert("操作失败");
	};
   
    // Remove progressively enhanced content class, just before creating the module
    YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");
	// Instantiate the Dialog
	YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
							{ width : "450px",
                              height:"300px",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"保存", handler:handleSubmit, isDefault:true },
								      { text:"取消", handler:handleCancel } ]
							});
    YAHOO.util.Dom.removeClass("dialog2", "yui-pe-content");
    YAHOO.example.container.dialog2= new YAHOO.widget.Dialog("dialog2", 
							{ width : "450px",
                              height:"360px",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"保存", handler:handleSubmit1, isDefault:true },
								      { text:"取消", handler:handleCancel1 } ]
							});
	// Validate the entries in the form to require that both first and last name are entered
	YAHOO.example.container.dialog1.validate = function() {
		var data = this.getData();
		if (data.firstname == "" || data.lastname == "") {
			alert("Please enter your first and last names.");
			return false;
		} else {
			return true;
		}
	};
	YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.render();
	YAHOO.util.Event.addListener("btnAddNew", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
    YAHOO.util.Event.addListener("btnCheck", "click", YAHOO.example.container.dialog2.show, YAHOO.example.container.dialog2, true);
	//YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
});
    </script>
      <script type="text/javascript" src="../Scripts/yui.list.YUITreeList.js"></script>               
<script src="../Scripts/yui.list.YUITreeList.button.event.js" type="text/javascript"></script>
<script>
    YAHOO.util.Event.addListener(document, 'keydown', function (ev) {
        if (ev.ctrlKey && ev.keyCode == "72") {
            fnModuleHelp();
            //alert("帮助");
        }
        if (ev.ctrlKey && ev.keyCode == "83") {

            fnListSetting();
            //alert("设置");
        }
    });
</script>
</asp:Content>